﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Automation.Protocols.Dal;
using System.Xml.Linq;
using System.Xml;
using Common.Logging;
using SupportLibrary;


namespace Automation.DAL.XML.Dao
{
   public class TCaseXMLDao:TestCaseBase    
    {
       private XElement root;
       private static ILog log = LogManager.GetLogger(typeof(TCaseXMLDao));
       List<TestCase> listTCase = new List<TestCase>();

       public TCaseXMLDao(string filePath)
       {
           try
           {
               root = XElement.Load(filePath);
               var testcases =
           from tcaseElement in root.Elements(Resources.Infor.TestCaseElement)
           select new TestCase
           {
               ID = (string)(tcaseElement.Element(Resources.Infor.TCaseID)),
               Name = (string)tcaseElement.Element(Resources.Infor.TCaseName),
               Behavior = (string)tcaseElement.Element(Resources.Infor.TCaseBehavior),
               Parameters = (string)tcaseElement.Element(Resources.Infor.TCaseParameters),
               State = (string)tcaseElement.Element(Resources.Infor.TCaseState)
           };
               foreach (TestCase t in testcases)
               {

                   listTCase.Add(t);
               }
           }catch(Exception e)
           {
               log.Error(Resources.Infor.LoadFileErr + filePath + e.Message);
               throw new Exception(Resources.Infor.LoadFileErr + filePath);
               
           }

       }
      
        public override List<TestCase> getTestcases()
        {
       
            return listTCase;
        }

        public override string getTestString()
        {
            throw new NotImplementedException();
        }
    }
}
